#include "RenderMesh.h"

namespace Nezha
{
	RenderMesh::RenderMesh(GeometryData* gd)
		:mGeometryDataPtr(gd)
		,mVBAccessor(NULL)
	{

	}

	RenderMesh::~RenderMesh()
	{
		if(mVBAccessor)
		{
			NZ_Delete mVBAccessor;
		}

		mGeometryDataPtr = NULL;
	}

	VertexBufferAccessor* RenderMesh::beginAccess()
	{
		if(!mVBAccessor)
		{
			mVBAccessor = NZ_New VertexBufferAccessor();
		}

		if(mGeometryDataPtr.ptr())
		{
			if(mVBAccessor->accessProcessing())
			{
				return NULL;
			}

			if(mVBAccessor->beginAccess(mGeometryDataPtr))
			{
				return mVBAccessor;
			}
		}

		return NULL;
	}

	void RenderMesh::endAccess()
	{
		if(mVBAccessor && mVBAccessor->accessProcessing())
		{
			mVBAccessor->endAccess();
		}
	}
}